/*
 * Copyright (c) 2020 ymyuan
 * Cloud is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

package com.totem.base.constants;

import lombok.Getter;
import lombok.Setter;

/**
 * 自定义返回码
 *
 * @author raymond
 */

public enum ErrorCode {
    // base
    OK(200, "ok"),
    BAD_REQUEST(400, "bad request"),

    UNAUTHORIZED(401, "unauthorized"),
    FORBIDDEN(403, "forbidden"),
    //NOT_FOUND(404, "not found"),
    //METHOD_NOT_ALLOWED(405, "method not allowed"),
    //REQUEST_TIMEOUT(408, "request timeout"),
    ERROR(500, "error"),

    // common
    ADD_DATA_ERROR(10000, "添加数据错误"),
    CLOUD_S3_ERROR(10001, "云平台S3配置错误"),

    // admin
    LOCAL_CONFIG_ERROR(20000, "配置错误,请联系管理员"),
    NOT_EXIST_CONFIG(20001, "应用配置不存在"),
    FILE_UPLOAD_ERROR(20002, "文件上传错误"),
    FILE_UPLOAD_IMG_TOO_LARGE(20003, "上传图片太大"),
    FILE_UPLOAD_VIDEO_TOO_LARGE(20004, "上传视频太大"),
    CANNOT_ACCESS(20005, "禁止访问"),
    REQUIRED_IMG_URL(20006, "图片地址必填"),

    // customer
    EXISTS_MOBILE(30000, "手机号和国家码已存在"),
    EXISTS_EMAIL_NICKNAME(30001, "邮箱或昵称已存在"),
    EXISTS_EMAIL(30002, "邮箱已存在"),
    EXISTS_NICKNAME(30003, "昵称已存在"),
    CANNOT_USE_INVITE_CODE(30004, "邀请码不可用"),
    NOT_EXIST_CUSTOMER(30005, "客户不存在"),
    REQUIRED_MOBILE(30006, "手机号和国家码必填"),
    REQUIRED_EMAIL(30007, "电子邮箱必填"),
    REQUIRED_EMAIL_MOBILE(30008, "电子邮箱或手机号必填"),
    REQUIRED_TX_AMOUNT(30009, "交易金额必填"),
    REQUIRED_PASSWORD(30010, "密码必填"),
    REQUIRED_TX_PASSWORD(30011, "交易密码必填"),
    REQUIRED_CUSTOMER_ID(30012, "CustomerId必填"),
    TX_PASSWORD_ERROR(30013, "交易密码错误"),
    PASSWORD_ERROR(30014, "密码错误"),
    PASSWORD_OLD_ERROR(30015, "不能使用旧密码"),
    REQUIRED_NICKNAME(30016, "昵称必填"),
    REPEAT_NICKNAME(30017, "昵称重复"),
    NOT_EXIST_MEMBER(30018, "会员不存在"),
    NOT_EXIST_NICKNAME(30020, "昵称未注册"),
    NOT_EXIST_MOBILE(30021, "手机未注册"),
    NOT_EXIST_EMAIL(30022, "邮箱未注册"),
    STOPPED_CUSTOMER(30023, "客户已被封号"),
    REQUIRED_VERIFICATION_CODE(30024, "验证码必填"),
    ERROR_VERIFICATION_CODE(30025, "验证码校验错误"),
    EXPIRE_VERIFICATION_CODE(30026, "验证码过期"),
    GENERATE_FAILED(30027, "钱包生成失败"),

    // order
    INSUFFICIENT_BALANCE(40000, "余额不足"),
    INSUFFICIENT_TX_AMOUNT(40001, "交易金額不足"),
    TX_AMOUNT_ERROR(40002, "交易金额错误"),
    TX_FAILED(40003, "交易失败"),
    PURCHASE_LIMIT(40004, "已限购,无法购买"),
    ORDER_PRICE_CONFLICT(40005, "订单金额与产品价格不符"),
    NOT_EXIST_WALLET(40006, "钱包不存在"),
    NOT_EXIST_TX_PASSWORD(40007, "交易密码不存在"),
    NOT_EXIST_ADDRESS_CUSTOMER(40008, "地址无关联的客户"),
    REQUIRED_ADDRESS(40009, "地址必填"),
    REQUIRED_ACCOUNT_ADDRESS(400010, "账户地址必填"),
    ADDRESS_FORMAT_ERROR(400011, "地址格式错误"),

    NOT_EXIST_ORDER(40020, "订单不存在"),
    NOT_EXIST_ORDER_ITEM(40021, "订单项不存在"),
    ORDER_CANCEL(40022, "订单已取消"),
    ORDER_DISABLE(40023, "订单已失效"),
    ORDER_FINISHED(40024, "订单已支付"),
    NOT_EXIST_SUBSCRIBE(400025, "认购包配置不存在"),
    ORDER_NOT_BELONG_CUSTOMER(40026, "订单不属于当前用户"),
    NOT_EXIST_CUSTOMER_SUBSCRIBE(40027, "客户的认购包不存在"),
    FINISHED_CANNOT_CANCEL(40028, "已完结的订单不能取消"),
    ORDER_CANNOT_DELETE(40029, "不能删除订单"),
    PAYMENT_TIMEOUT(40030, "支付超时"),
    NOT_EXIST_ORDER_NO(40031, "订单编号必填"),
    NOT_EXIST_WALLET_JOURNAL(40032, "订单的资金流水不存在"),
    REQUIRED_ACCEPT(40033, "接受标志必填"),
    HANDLING_CANNOT_CANCEL(40034, "处理中的订单不能取消"),

    // product
    NOT_EXIST_PRODUCT(41000, "产品不存在"),
    NOT_EXIST_PRODUCT_INV(41001, "产品库存不存在"),
    REQUIRED_PRODUCT_ID(41002, "ProductId必填"),

    // infomation
    REQUIRED_TITLE(41010, "标题必填"),
    REQUIRED_INFOMATION_ID(41011, "资讯Id必填"),

    // enums
    ILLEGAL_LOGIN_TYPE(50000, "参数LoginType取值异常"),
    ILLEGAL_FILE_TYPE(50001, "参数FileType取值异常"),
    ILLEGAL_PAYMENT_STATE(50002, "参数PaymentState取值异常"),
    ILLEGAL_CRYPTO_CURRENCY(50003, "参数CryptoCurrency取值异常"),
    ILLEGAL_CURRENCY(50004, "参数Currency取值异常"),
    ILLEGAL_SUBSCRIBE_NAME(50005, "参数SubscribeName取值异常"),
    ILLEGAL_HANDLE_STATE(50006, "参数Handle取值异常"),
    ILLEGAL_OPERATE_TYPE(50007, "参数OperateType取值异常"),
    ILLEGAL_JOURNAL_TYPE(50008, "参数JournalType取值异常"),
    ILLEGAL_DIRECTION(50009, "参数Direction取值异常"),
    ILLEGAL_SWITCH(50010, "参数Switch取值异常"),
    ILLEGAL_STATE(50011, "参数State取值异常"),
    ;


    @Getter
    @Setter
    private int code;
    @Getter
    @Setter
    private String message;

    ErrorCode(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public static ErrorCode getResultEnum(int code) {
        for (ErrorCode type : ErrorCode.values()) {
            if (type.getCode() == code) {
                return type;
            }
        }
        return ERROR;
    }

    public static ErrorCode getResultEnum(String message) {
        for (ErrorCode type : ErrorCode.values()) {
            if (type.getMessage().equals(message)) {
                return type;
            }
        }
        return ERROR;
    }
}